package com.ofps.forms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ofps.forms.common.utils.R;
import com.ofps.forms.mapper.OptionMapper;
import com.ofps.forms.domain.Option;
import com.ofps.forms.service.OptionService;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Service("optionService")
public class OptionServiceImpl extends ServiceImpl<OptionMapper, Option> implements OptionService {

    @Resource
    private OptionMapper optionMapper;

    @Override
    public R delete(Map<String, Object> body) {
        QueryWrapper<Option> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", body.get("id"));
        return optionMapper.delete(queryWrapper) == 1 ? R.ok("删除成功！") : R.error("删除失败！");
    }

    @Override
    public List<Option> queryWithId(Map<String, Object> body) {
        QueryWrapper<Option> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("question_id", body.get("question_id").toString());
        List<Option> optionList = optionMapper.selectList(queryWrapper);
        System.out.println(optionList.size());
        return optionList;
    }

    @Override
    public Option queryWithOptionId(String Option_id, String question_id) {
        System.out.println("Option_id" + Option_id);
        QueryWrapper<Option> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_id", Option_id).eq("question_id", question_id);
        List<Option> optionList = optionMapper.selectList(queryWrapper);
        if (optionList.isEmpty() == false)
            return optionList.get(0);
        else
            return null;
    }

}
